package xin.marcher.module.replenished.api.impl;

import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import xin.marcher.module.common.core.JsonResult;
import xin.marcher.module.common.exception.ProductBizException;
import xin.marcher.module.replenished.api.CompensationApi;
import xin.marcher.module.replenished.domain.request.CompensationRequest;
import xin.marcher.module.replenished.service.CompensationService;

import javax.annotation.Resource;

/**
 * 商品可补实现
 *
 * 
 */
@Slf4j
@DubboService(version = "1.0.0", interfaceClass = CompensationApi.class, retries = 0)
public class CompensationApiImpl implements CompensationApi {
    @Resource
    private CompensationService compensationService;

    @Override
    public JsonResult syncCompensationProduct(CompensationRequest request) {
        try {
            return compensationService.syncCompensationProduct(request);
        } catch (ProductBizException e) {
            log.error("biz error: ", e);
            return JsonResult.buildError(e.getErrorCode(), e.getErrorMsg());
        } catch (Exception e) {
            log.error("system error: ", e);
            return JsonResult.buildError(e.getMessage());
        }
    }
}
